
tinymce.PluginManager.add('input', function(editor, url){

    editor.ui.registry.addButton('input', {
        icon: 'duplicate-row',
        tooltip: '插入输入框',
        onAction: ()=>{
            var id = Math.uuid().toLowerCase();
            editor.insertContent(' <textarea class="mce-textarea" data-id="' + id +'"></textarea>')
        },
        onSetup: ()=>{
        }
    });

    editor.on('init', function () {
        const body = editor.contentDocument.body;
        if ($(body).hasClass("view_body")) {
            return;
        }
        body.addEventListener('input', function(e) {
            var $target = $(e.target);
            if ($target.is("textarea")) {
                $target[0].innerHTML = $target.val();
                if ($target.val()) {
                    $target.removeClass("textarea-blank");
                } else {
                    $target.addClass("textarea-blank");
                }
                if (!$target.attr("data-id")) {
                    $target.attr("data-id", Math.uuid().toLowerCase());
                }
            }
        }, false);
    });

    return {
        getMetadata: function () {
          return  {
            name: "input",//插件名称
            url: "http://exampleplugindocsurl.com", //作者网址
          };
        }
    };

})